﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Mail;
namespace MainWebService
{
    public class Emailer
    {
        public string To { get; set; }
        public string Subject { get; set; }
        public string MailBody { get; set; }
        public string CC { get; set; }
        public string BCC { get; set; }
        public Attachment File { get; set; }
        public Emailer(string to,string subject)
        {
            this.To = to;
            this.Subject = subject;
        }
        public Emailer()
        {

        }

       public bool SendMail()
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.To.Add(new MailAddress(To));
                msg.From =new MailAddress("no-reply@ssica.org");
                if (!string.IsNullOrWhiteSpace(CC))
                {
                    string[] ccmailIds = CC.Split(',');
                    for (int i = 0; i < ccmailIds.Length; i++)
                    {
                        msg.CC.Add(ccmailIds[i]); 
                    }
                   
                }
                msg.Bcc.Add(new MailAddress("dharmendra.hbti@gmail.com"));
                if (!string.IsNullOrWhiteSpace(BCC))
                {
                    msg.Bcc.Add(BCC);
                }
                msg.Subject = Subject;
                msg.Body = MailBody;
                if (File!=null)
                {
                    msg.Attachments.Add(File);
                    
                }
                msg.IsBodyHtml = true;
                SmtpClient _client = new SmtpClient();
                _client.Send(msg);
                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }
    }
}